﻿using Lamex.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mIE.Calculate
{
    public class LGC_VAL_BOM_SUB3
    {
        public static DataTable LGC_VAL_BOM_SUB3_VALUE(string Feature_CheckA, string Feature_CheckB, double W_VALUE, DataTable dt_BOM,
            string DWG_No, string Part_No, string Process_Code, string WORKTIME_LOGIC_CODE)
        {
            //"子程序3，参数：检查特征A，检查特征B，阔度
            //a、遍历抽出BOM数据中的[BOM].[COMPONENT]
            //b、返回逻辑
            //IF [BOM].[COMPONENT]首字符为""3""，
            //   根据[BOM].[COMPONENT]抽出尺寸数据，表为[IE_Part_SizeParmList].[WIDTH]
            //   IF [WIDTH]<=阔度
            //     检查特征A=检查特征A+[BOM].[SINGLE_QTY]
            //   ELSE
            //     检查特征B=检查特征B+[BOM].[SINGLE_QTY]
            //   END IF
            //END IF"
            DataTable dtFeature_List = Common.GetTable.GetTable_Feature();
            double Feature_CheckA_VALUE = 0, Feature_CheckB_VALUE = 0;
            double W = 0;
            if (dt_BOM.Rows.Count > 0)
            {
                for (int i = 0; i < dt_BOM.Rows.Count; i++)
                {
                    //图纸号不为空才执行
                    if (dt_BOM.Rows[i]["COMPONENT"].ToString().Substring(0, 1) != "3")
                        continue;
                    //根据BOM部件号COMPONENT查询得到尺寸参数L,【IE_Part_SizeParmList】
                    DataTable dtTemp = BaseBuildSql.GetDataTableBySql("select WIDTH from IE_Part_SizeParmList where PART_NO='" + dt_BOM.Rows[i]["COMPONENT"].ToString() + "'");
                    //if (dtTemp.Rows.Count <= 0)
                    //    W = 0;
                    if (dtTemp.Rows.Count <= 0 || dtTemp.Rows[0]["WIDTH"].ToString().Trim().Length <= 0)
                        continue;
                    else
                        W = dtTemp.Rows[0]["WIDTH"].ToString().Length > 0 ?
                            Convert.ToDouble(dtTemp.Rows[0]["WIDTH"].ToString()) : 0;
                    double SINGLE_QTY = dt_BOM.Rows[i]["SINGLE_QTY"].ToString().Length > 0 ?
                        Convert.ToDouble(dt_BOM.Rows[i]["SINGLE_QTY"].ToString()) : 0;
                    if (W <= W_VALUE)
                        Feature_CheckA_VALUE = Feature_CheckA_VALUE + SINGLE_QTY;
                    else
                        Feature_CheckB_VALUE = Feature_CheckB_VALUE + SINGLE_QTY;
                }
                if (Feature_CheckA_VALUE > 0)
                {
                    DataRow dr = dtFeature_List.NewRow();
                    dr["DWG_NO"] = DWG_No;
                    dr["PART_NO"] = Part_No;
                    dr["PROCESS_CODE"] = Process_Code;
                    dr["FEATURE_NAME"] = Feature_CheckA;
                    dr["FEAT_VALUE"] = Feature_CheckA_VALUE;
                    dr["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, Feature_CheckA, "", Feature_CheckA_VALUE);//根据特征定义表工时字段计算
                    dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                    dtFeature_List.Rows.Add(dr);
                }
                if (Feature_CheckB_VALUE > 0)
                {
                    DataRow dr1 = dtFeature_List.NewRow();
                    dr1["DWG_NO"] = DWG_No;
                    dr1["PART_NO"] = Part_No;
                    dr1["PROCESS_CODE"] = Process_Code;
                    dr1["FEATURE_NAME"] = Feature_CheckB;
                    dr1["FEAT_VALUE"] = Feature_CheckB_VALUE;
                    dr1["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, Feature_CheckB, "", Feature_CheckB_VALUE);//根据特征定义表工时字段计算
                    dr1["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    dr1["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                    dtFeature_List.Rows.Add(dr1);
                }
            }
            return dtFeature_List;
        }
    }
}
